package com.yx.changdao.common.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.yx.changdao.common.annotation.AutoFill;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotEmpty;
import java.io.Serializable;
import java.util.Date;
import java.util.Optional;

/**
 * 权限表
 *
 * @author zhangqi
 * @date 2019-11-06 11:21:05
 */
@TableName(SysPermission.TABLE_NAME)
public class SysPermission implements Serializable {
    private static final long serialVersionUID = 1L;

    public static final String TABLE_NAME = "sys_permission";

    /**
     * 权限ID
     */
    public static final String PERM_ID = "perm_id";
    /**
     * 权限名称
     */
    public static final String PERM_NAME = "perm_name";
    /**
     * 创建时间
     */
    public static final String CREATE_TIME = "create_time";


    /**
     * 权限ID
     */
    @NotEmpty(message = "权限id不能为空")
    @Length(min = 1, max = 32, message = "权限id只能在1~32位之间")
    @TableId(type = IdType.ASSIGN_ID)
    private String permId;
    /**
     * 权限名称
     */
    @NotEmpty(message = "权限名称不能为空")
    @Length(min = 1, max = 32, message = "权限名称只能在1~32位之间")
    private String permName;
    /**
     * 创建时间
     */
    @AutoFill
    @TableField(fill = FieldFill.INSERT)
    private Date createTime;


    public String getPermId() {
        return this.permId;
    }

    public void setPermId(String permId) {
        this.permId = permId;
    }

    public String getPermName() {
        return this.permName;
    }

    public void setPermName(String permName) {
        this.permName = permName;
    }

    public Date getCreateTime() {
        return this.createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    /**
     * 获取权限描述前缀
     *
     * @return
     */
    public String permissionDescribe() {
        String[] permissionDescribes = this.getPermName().split(":|：");

        return Optional.ofNullable(permissionDescribes).orElse(new String[]{""})[0];
    }
}
